<?php defined('SYSPATH') or die('No direct script access.');

//采购支持界面
class Controller_advancewarning extends Controller_Admin{

  public function before()
  {
    try
    {
      ACL::Required('purchase advancewarning');
    }
    catch(HTTP_Exception_403 $e)
    {
      $this->request->redirect(URL::base(true));
    }

    parent::before();
  }

//采购支持界面 销量统计 model链接
  public function action_index()
  {    
      $this->title   = "采购支持";
      set_time_limit ( 0 );
      if(isset($_GET['sku']) and trim($_GET['sku']))
      {

      $sku = trim($_GET['sku']);
      
      $sku_warning = service_warninglist::warning_sku_all($sku);//sku预警信息
      
	
      $sku_detailed=service_skudetail::load_sku_info_all($sku);//得到SKU的基本信息 
      
  	  $sku_providers=service_skudetail::sku_providers($sku);//得到SKU的相关供应商
      
      $count_days = 90;
      $start = date("Y-m-d",strtotime('now - '.$count_days.' days'));//
      
      $sale = Service_warning::get_sale_history($start,$count_days,$sku);//历史销量
      $inventory = Service_warning::get_inventory_history($start,$count_days,$sku);//历史库存
      $purchase = Service_warning::get_purchase_history($start,$count_days,$sku);//历史采购
      //var_dump($sale);exit;

      $purchase_details = Service_Warning::get_purchase_by_sku($sku);//采购明细

      }

      $view     = View::factory('warning/advancewarning');   

      $view->set('sku_detailed',isset($sku_detailed)?$sku_detailed:NULL);
      $view->set('sku_providers',isset($sku_providers)?$sku_providers:NULL);
      $view->set('sku_warning',isset($sku_warning[0])?$sku_warning[0]:NULL);
      $view->set('purchase_details',isset($purchase_details)?$purchase_details:NULL);
      $view->set('sale',isset($sale)?$sale:NULL);
      $view->set('inventory',isset($inventory)?$inventory:NULL);
      $view->set('purchase',isset($purchase)?$purchase:NULL);

      $this->response->body($view);
    
  }

}
?>
